package com.example.hasee.weather;

import android.util.Log;

import com.example.hasee.data.entity.Weather;

import org.json.JSONException;
import org.json.JSONObject;

public class WeatherInfoParse {
    private WeatherInfoParse(){
    }
    public static Weather parseInfo(String jsonString){
        Weather w=new Weather();
        //根据json的层数，一级一级的解析
        try {
            JSONObject root =new JSONObject(jsonString);
            JSONObject result=root.getJSONObject("result");
            JSONObject today=result.getJSONObject("today");
            String temperature=today.getString("temperature");
            w.setTemperature(temperature);
            String weather=today.getString("weather");
            w.setWeather(weather);
            JSONObject weather_id=today.getJSONObject("weather_id");
            String fa=weather_id.getString("fa");
            w.setFa(fa);
        } catch (JSONException e) {
            Log.e("MyLog",e.getMessage());
        }
        return w;
    }
}
